package com.changgou.common.exception;

//import com.changgou.common.constant.StatusCode;
//import com.changgou.common.vo.Result;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;

import com.changgou.common.constant.StatusCode;
import com.changgou.common.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类：能够拦截controler的请求
 * 针对controller处理器抛出的异常进行统一处理：//根据返回或处理器处理的结果进行 处理
 * 返回Result
 */
@ControllerAdvice
public class BaseExceptionHandler {
    /**
     * 处理异常
         * @param e 异常类型
         * @return 处理结果
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR,e.getMessage());
    }
}
